import login from '@/api/login/index.js'
import menu from '@/api/menu/index.js'
import request from '@/api/utils/request.js'

const config = {
    ...login,
    ...menu
}

export default (funName, data = {}, isToken=false) => {
    let newConfig = JSON.parse(JSON.stringify(config[funName]))
    if(data){
        newConfig.url = newConfig.url.replace(/\{([\d-_\w]+)\}/g,(word, $1)=>{
            let res = data[$1]
            delete data[$1]
            return res
        })
    }
    return request({
        url: newConfig.url,
        method: newConfig.method,
        data: data,
        isToken: isToken
    })
}